import instance from "@/utils/request"

// 获取图形验证码图片
export const getCodeImage = function(){
    return instance.get('captcha/image')
}

// 发送验证码
export const getPhoneCode = function(captchaCode,captchaKey, mobile ){
    return instance.post('captcha/sendSmsCaptcha', {
      "captchaCode": captchaCode,
      "captchaKey": captchaKey,
      "mobile": mobile
    })
}

// 登录
export const loginRequest = function(phoneNum) {
    return instance.post('passport/login', {
        "form" : {
            "smsCode": 246810,
            "mobile": phoneNum,
            "isParty": false,
            "partyData": {}
        }
      })
}

// 首页数据
export const getHomePageData = function(){
    
    return instance.get('page/detail')
}

// 搜索列表数据
export const searchList = (obj)=>{
    const {sortType, sortPrice, categoryId, goodsName, page} = obj
    return instance.get('/goods/list', {
        params: {
            sortType,
            sortPrice, 
            categoryId,
            goodsName,
            page
        }
    })

}

// 商品详情页
export const getGoodsDetailData = (id) => {
    return instance.get('/goods/detail', {
        params: {
            goodsId: id
        }
    })
}

// 获取商品评论
export const getGoodsComment = (goodsId) => {
    const limit = 10
    return instance.get('/comment/listRows', {
        params: {
            goodsId,
            limit,  
        }
    })
}

// 加入购物车
export const addCartNetwork = (obj)=>{

    return instance.post('/cart/add', obj)
}

// 获取购物车列表数据
export const getCartList = ()=>{
    return instance.get('/cart/list')
}

// 修改购物车商品数量
export const changePrdCount = (obj)=>{
    // console.log(obj)
    return instance.post('/cart/update', obj)
}

// 删除购物车数据
export const deleteCartPrds = (obj)=>{
    return instance.post('/cart/clear', obj)
}

// 
export const getCheckOrder = (mode, obj) => {

    const params = {
        "mode": mode,
        "delivery": 10,
        "payType": 10,
        "couponId": 0,
        "isUsePoints": 0,
        ...obj
      }

    return instance.get('/checkout/order', {
        params: params
    })
}

// 用户收货地址列表
export const getAddressList = ()=>{
    return instance.get('/address/list')
}

// 省市区地址
export const getRegion = ()=>{
    return instance.get('/region/tree')
}